import "package:flutter/material.dart";
import "package:myapp/_widget/swiper.dart";

// 轮播图类型推荐的轮播图类
class RecommendItemSwiperItem {
  String title;
  String imageUrl;
  String? path;
  RecommendItemSwiperItem({
    required this.title,
    required this.imageUrl,
    this.path,
  });
}

// 轮播图类型
class RecommendItemSwiperItemWidget extends StatelessWidget {
  final List<RecommendItemSwiperItem> recommendItemSwiperList;
  const RecommendItemSwiperItemWidget({
    super.key,
    required this.recommendItemSwiperList,
  });
  @override
  Widget build(BuildContext context) {
    return AspectRatio(
      aspectRatio: 16 / 9,
      child: Container(
        decoration: BoxDecoration(color: Colors.pink.shade200),
        child: LayoutBuilder(
          builder: (context, constraints) {
            return Swiper(
              showIndicator: true,
              indicatorAlignment: Alignment.bottomCenter,
              indicatorMainAxisAlignment: MainAxisAlignment.end,
              height: constraints.maxHeight,
              onCurrentIndexChange: (val) {},
              loop: true,
              auto: true,
              animatedDuration: const Duration(milliseconds: 200),
              duration: const Duration(milliseconds: 1800),
              children: recommendItemSwiperList.map((e) {
                return Stack(
                  alignment: Alignment.bottomCenter,
                  children: [
                    SizedBox(
                      width: double.infinity,
                      child: Image.asset(
                        e.imageUrl,
                        fit: BoxFit.cover,
                      ),
                    ),
                    Container(
                      width: double.infinity,
                      padding:
                          const EdgeInsets.only(bottom: 6, left: 8, top: 10),
                      decoration: const BoxDecoration(
                        gradient: LinearGradient(
                            begin: Alignment.bottomCenter,
                            end: Alignment.topCenter,
                            colors: [
                              Color.fromARGB(150, 0, 0, 0),
                              Color.fromARGB(100, 0, 0, 0),
                              Color.fromARGB(50, 0, 0, 0),
                              Color.fromARGB(0, 0, 0, 0),
                            ]),
                      ),
                      child: Row(
                        children: [
                          SizedBox(
                            width: constraints.maxWidth / 2,
                            child: Text(
                              e.title,
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                              style: const TextStyle(
                                color: Colors.white,
                                fontWeight: FontWeight.bold,
                                fontSize: 14,
                              ),
                            ),
                          )
                        ],
                      ),
                    )
                  ],
                );
              }).toList(),
            );
          },
        ),
      ),
    );
    //   },
    // );
  }
}
